<?php
	session_start();
	require 'include/configDB.php';

	// if (!isset($_SESSION['role']) || ($_SESSION['role'] != "Guru") || ($_SESSION['role'] != "Admin")) {
	// 	// redirect ke page login
	// 	header('Location: login.php');
	// }

	 $query_tahun_ajaran = mysql_query("SELECT MAX(tahun_ajaran) as max_tahun_ajaran FROM tahun_ajaran");
	 $tahun_ajaran = mysql_fetch_assoc($query_tahun_ajaran);
	 $last_id_tahun_ajaran = $tahun_ajaran['max_tahun_ajaran'];

	  if (! isset($_SESSION['role']) || ($_SESSION['role'] != "Admin") && ($_SESSION['role'] != "Staff Tata Usaha")) {
  		header('Location: login.php');
	}
?>

<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Input Data Siswa</title>
<link rel="stylesheet" type="text/css" href="style.css" />
<script type="text/javascript" src="jquery.min.js"></script>
<script type="text/javascript" src="ddaccordion.js"></script>
<script type="text/javascript">
ddaccordion.init({
	headerclass: "submenuheader", //Shared CSS class name of headers group
	contentclass: "submenu", //Shared CSS class name of contents group
	revealtype: "click", //Reveal content when user clicks or onmouseover the header? Valid value: "click", "clickgo", or "mouseover"
	mouseoverdelay: 200, //if revealtype="mouseover", set delay in milliseconds before header expands onMouseover
	collapseprev: true, //Collapse previous content (so only one open at any time)? true/false 
	defaultexpanded: [], //index of content(s) open by default [index1, index2, etc] [] denotes no content
	onemustopen: false, //Specify whether at least one header should be open always (so never all headers closed)
	animatedefault: false, //Should contents open by default be animated into view?
	persiststate: true, //persist state of opened contents within browser session?
	toggleclass: ["", ""], //Two CSS classes to be applied to the header when it's collapsed and expanded, respectively ["class1", "class2"]
	togglehtml: ["suffix", "<img src='images/plus.gif' class='statusicon' />", "<img src='images/minus.gif' class='statusicon' />"], //Additional HTML added to the header when it's collapsed and expanded, respectively  ["position", "html1", "html2"] (see docs)
	animatespeed: "fast", //speed of animation: integer in milliseconds (ie: 200), or keywords "fast", "normal", or "slow"
	oninit:function(headers, expandedindices){ //custom code to run when headers have initalized
		//do nothing
	},
	onopenclose:function(header, index, state, isuseractivated){ //custom code to run whenever a header is opened or closed
		//do nothing
	}
})
</script>

<script type="text/javascript" src="jconfirmaction.jquery.js"></script>
<script type="text/javascript">

	function cekuser(a) {
	var re = /^[a-zA-Z\s]+$/;
	return re.test(a);
	}

	function validateEmail(email) { 
	    var re = /^(([^<>()[\]\\.,;:\s@\"]+(\.[^<>()[\]\\.,;:\s@\"]+)*)|(\".+\"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/;
	    return re.test(email);
	} 


	function phonenumber(inputtxt)  
	{  
	  var reg = new RegExp("^[0][0-9]{7,14}([ ]?[\\,|\\;][ ]?[0][0-9]{7,14})*$");

	  return reg.test(phoneValue);
	} 

	function allNumber(input){
		var numbers = /^[0-9]+$/;
		return numbers.test(input);
	}

	function alphaNumeric(input){
		var letters = /^[0-9a-zA-Z\s]+$/;
		return letters.test(input);
	}

	function validasi() {
		var NIS  = document.getElementById("NIS").value;
		var nama = document.getElementById("nama").value; 
		var tempat_lahir = document.getElementById("tempat_lahir").value; 
		var nama_ayah = document.getElementById("nama_ayah").value; 
		var nama_ibu = document.getElementById("nama_ibu").value; 
		var no_tlp = document.getElementById("no_tlp").value; 
		var email = document.getElementById("email_wali").value; 
		var agama = document.getElementById("agama").value;
		var alamat = document.getElementById("alamat").value;
		var no_tlp = document.getElementById("no_tlp").value;
		var smp_asal = document.getElementById("smp_asal").value;;
		var ijazah = document.getElementById("no_ijazah").value;
		var nama_ayah = document.getElementById("nama_ayah").value;
		var nama_ibu = document.getElementById("nama_ibu").value;;
		var pekerjaan_ayah = document.getElementById("pekerjaan_ayah").value;
		var pekerjaan_ibu = document.getElementById("pekerjaan_ibu").value;
		var nama_wali = document.getElementById("nama_wali").value;
		var alamat_wali = document.getElementById("alamat_wali").value;
		var no_tlp_wali = document.getElementById("no_tlp_wali").value;
		var pekerjaan_wali = document.getElementById("pekerjaan_wali").value;
	
		if(NIS == "" ){
			alert("NIS harus diisi");
			return false;
		}

		if( document.input_data.tingkat.value == "NULL" )
	   	{
		    alert( "Tingkat harus di isi" );
		    return false;
	    }
	   
	   if( document.input_data.jurusan.value == "NULL" )
	   {
	     alert( "Jurusan harus di isi" );
	     return false ;
	   }
	   
	   if( document.input_data.no_kelas.value == "NULL" )
	   {
	     alert( "No Kelas harus di isi" );
	     return false;
	   }
	   
		if(nama == "" ){
			alert("nama harus diisi");
			return false;
		}

		if(tempat_lahir==""){
			alert("tempat lahir harus di isi");
			return false;
		}

		if( document.input_data.tanggal_lahir.value == "NULL" )
	   	{
	     	alert( "Tanggal Lahir harus di isi" );
	    	return false;
	    }

	    if( document.input_data.bulan_lahir.value == "NULL" )
	   	{
		     alert( "bulan lahir harus di isi" );
		     return false;
	    }

	    if( document.input_data.tahun_lahir.value == "NULL" )
	   	{
		    alert( "Tahun Lahir harus di isi" );
		    return false;
	    }

	    if(agama==""){
			alert("agama harus di isi");
			return false;
		}

		//jenis kelamin

		if(alamat==""){
			alert("alamat harus di isi");
			return false;
		}

		if( document.input_data.kode_pos.value == "NULL" )
	   	{
	    	alert( "kode pos harus di isi" );
	    	return false;
	    }

	    if(no_tlp==""){
			alert("Nomor Telepon harus di isi");
			return false;
		}

		if(smp_asal==""){
			alert("Asal sekolah harus di isi");
			return false;
		}

		if(no_ijazah==""){
			alert("Nomor Ijazah harus di isi");
			return false;
		}

		if(nama_ayah==""){
			alert("Nama Ayah harus di isi");
			return false;
		}

		if(pekerjaan_ayah==""){
			alert("Pekerjaan ayah harus di isi");
			return false;
		}

		if(nama_ibu==""){
			alert("Nama ibu harus di isi");
			return false;
		}

		if(pekerjaan_ibu==""){
			alert("Pekerjaan ibu harus di isi");
			return false;
		}

		if(nama_wali==""){
			alert("Nama wali harus di isi");
			return false;
		}

		if(pekerjaan_wali==""){
			alert("Pekerjaan Wali harus di isi");
			return false;
		}

		if(alamat_wali==""){
			alert("Alamat wali harus di isi");
			return false;
		}

		if( document.input_data.kode_pos_wali.value == "NULL" )
	   	{
	     alert( "kode pos wali harus di isi" );
	     return false;
	    }

	    if(no_tlp_wali==""){
			alert("Nomor telepon wali harus di isi");
			return false;
		}

		if (!allNumber(NIS)) {
			alert("NIS harus berupa nomor semua!");
			return false;
		}


		if (!cekuser(nama)) {
			alert("Nama harus berupa HURUF semua! ");
			return false;
		}


		if (!cekuser(tempat_lahir)) {
			alert("Tempat Lahir harus berupa HURUF semua! ");
			return false;
		}

		if (!cekuser(agama)) {
			alert("Agama harus berupa HURUF semua! ");
			return false;
		}

		if (!alphaNumeric(alamat)) {
			alert("Alamat tidak boleh mengandung ! @ # / $ % &");
			return false;
		}

		if(!phonenumber(no_tlp)){
			alert("No Telepon harus berupa Angka semua! ");
			return false;
		}

		if (!alphaNumeric(smp_asal)) {
			alert("Sekolah Asal tidak boleh mengandung ! @ # / $ % &");
			return false;
		}

		if (!allNumber(no_ijazah)) {
			alert("Nomor Ijazah harus berapa angka semua!");
			return false;
		}

		if (!cekuser(nama_ayah)) {
			alert("Nama Ayah harus berupa HURUF semua! ");
			return false;
		}

		if (!cekuser(pekerjaan_ayah)) {
			alert("Pekerjaan Ayah harus berupa HURUF semua! ");
			return false;
		}

		if (!cekuser(nama_ibu)) {
			alert("Nama ibu harus berupa HURUF semua! ");
			return false;
		}

		if (!cekuser(pekerjaan_ibu)) {
			alert("Pekerjaan Ibu harus berupa HURUF semua! ");
			return false;
		}

		if (!cekuser(nama_wali)) {
			alert("Nama wali harus berupa HURUF semua! ");
			return false;
		}

		if (!cekuser(pekerjaan_wali)) {
			alert("Pekerjaan wali harus berupa HURUF semua! ");
			return false;
		}

		if (!alphaNumeric(alamat_wali)) {
			alert("Alamat wali tidak boleh mengandung ! @ # / $ % &");
			return false;
		}

		if(!phonenumber(no_tlp_wali)){
			alert("No Telepon harus berupa Angka semua! ");
			return false;
		}
	}

</script>

<script language="javascript" type="text/javascript" src="niceforms.js"></script>
<link rel="stylesheet" type="text/css" media="all" href="niceforms-default.css" />
<style>
	<?php include 'include_style.php'; ?>
</style>
</head>
<body>
<div id="main_container">

	<?php include 'header.php'; ?>
    
    <div class="main_content">
                
                    
    <div class="center_content">  
    
	
    <div class="left_content">
    
    		<?php include 'left_content.php'; ?>
    		<?php include 'calendar.php' ; ?>

    </div>  
    
    <div class="right_content">
	<h2>Input Data Siswa</h2>
		<div id="stylized" class="myform">
			<form id="input_data" name="input_data" method="post" action="include/input_data_siswa.php" onsubmit='return validasi();'>
			<h1>Data Diri Siswa</h1>
			<table>
				<tr>
					<td width="250">
						<label>Nomor Induk Siswa<span class="small">isi nomor induk siswa</span></label>
					</td>
					<td>
						:
					</td>
					<td colspan="3">
						<input type="text" name="NIS" id="NIS" />
					</td>
				</tr>
				<tr>
					<td>
						<label>Tahun Masuk<span class="small">isi tahun masuk siswa</span></label>
					</td>
					<td>
						:
					</td>
					<td colspan="3">
						<input type="text" name="tahun_masuk" id="tahun_masuk" readonly value="<?php echo $last_id_tahun_ajaran; ?>" />
					</td>
				</tr>
				<tr>
					<td>
						<label>Kelas<span class="small">isi kelas</span></label>
					</td>
					<td>
						:
					</td>
					<td colspan="3">
						<select name="tingkat" id="tingkat">
							<option value="NULL">Pilih</option>
							<option value="10">10</option>
							<option value="11">11</option>
							<option value="12">12</option>	  	
						</select>
						<select name="jurusan">
							<option value="NULL">Pilih</option>
							<?php
							$query = mysql_query("SELECT * FROM jurusan");

							while ($data = mysql_fetch_assoc($query)) {
							?>
							<option value="<?php echo $data['id'];?>">
								<?php echo $data['nama'];?>
							</option>
							<?php } ?>
						</select>
						<select name="no_kelas" id="no_kelas">
							<option value="NULL">Pilih</option>
							<option value="1">1</option>
							<option value="2">2</option>
							<option value="3">3</option>	
						    <option value="4">4</option>
						    <option value="5">5</option>
						</select>
					</td>
				</tr>    
				<tr>
					<td>
						<label>Nama Lengkap<span class="small">Tambah nama siswa</span></label>
					</td>
					<td>
						:
					</td>
					<td colspan="3">
						<input type="text" name="nama" id="nama" /></td>
				</tr>
				<tr>
					<td>
						<label> Tempat lahir<span class="small">Tempat lahir siswa</span></label>
					</td>
					<td>
						:
					</td>
					<td colspan="3">
						<input type = "text" name = "tempat_lahir" id = "tempat_lahir"/>
					</td>
			   </tr>
			   <tr> 
					<td>  
						<label> Tanggal Lahir<span class="small">Tanggal lahir siswa</span></label>
					</td>
					<td>
						:
					</td>
					<td colspan="3">    
					   <select name='tanggal_lahir' id="tanggal_lahir">
					   	<option value="NULL">Pilih</option>
						<?php 
							for ($i = 1; $i <= 31; $i++) {
								?>
								<option value="<?php echo $i; ?>"><?php echo $i; ?></option>
							<?php
							}
						?>
						</select>	  
					   <select name='bulan_lahir' id ="bulan_lahir">
					   	<option value="NULL">Pilih</option>
						 <?php 
							for ($i = 1; $i < 13; $i++) {
								?>
								<option value="<?php echo $i; ?>"><?php echo $i; ?></option>
							<?php
							}
						?>
						</select>
						<select name='tahun_lahir' id="tahun_lahir">
						<option value="NULL">Pilih</option>
						<?php 
						for ($i = 2000; $i >= 1985; $i--) {
							?>
							<option value="<?php echo $i; ?>"><?php echo $i; ?></option>
							<?php
						}
						?>
						</select>
					</td>
				</tr>
				<tr>
					<td>
						<label>Agama<span class="small">isi agama siswa</span></label>
					</td>
					<td>
						:
					</td>
					<td colspan="3">
						<input type="text" name="agama" id="agama" />
					</td>
				</tr>
				<tr>
					<td>
						<label>Jenis Kelamin<span class="small">isi jenis kelamin siswa</span></label>
					</td>
					<td>
						:
					</td>
					<td width = "100">  
						<input type="radio" name="jenis_kelamin" id="jenis_kelamin_p" value="laki-laki">Laki-laki
					</td>
					<td >
						<input type="radio" name="jenis_kelamin" id="jenis_kelamin_w" value="perempuan">Perempuan
					</td>
				</tr>
				<tr>
					<td>
						<label>Alamat<span class="small">isi alamat siswa</span></label>
					</td>
					<td>
						:
					</td>
					<td colspan="3">
						<textarea rows="5" cols="24" name="alamat" id="alamat"></textarea>
					</td>
				</tr>
				<tr>
					<td>
						<label>Kodepos<span class="small">isi kodepos siswa</span></label>
					</td>
					<td>
						:
					</td>
					<td colspan="3">
						<select name="kode_pos" id="kode_pos">
							<option value="NULL">---------Pilih----------</option>
							<?php 
						        $kode_pos = mysql_query("SELECT * FROM kode_pos");  
								// $result = mysql_fetch_array($nama_jurusan);
						        while($kode_pos_data = mysql_fetch_array($kode_pos))
						        {
						   		?>  
									
        							<option value="<?= $kode_pos_data[0]; ?>"><?= $kode_pos_data['0']?></option>  
								<?php  
								}  
								?>  	
					    </select>		
					</td>
				</tr>
				<tr>
					<td>
						<label>No. Telepon/HP<span class="small">isi no telepon siswa</span></label>
					</td>
					<td>
						:
					</td>
					<td colspan="3">
						<input type="text" name="no_tlp" id="no_tlp" />
					</td>
				</tr>
            </table>
               
            <h1>Data Akademik SMP</h1>
            <table>
				<tr>
					<td width="250">
						<label>Nama SMP Asal
						 <span class="small">isi asal SMP siswa</span>
						</label>
					</td>
					<td>
						:
					</td>
					<td width="200">
						<input type = "text"  name = "smp_asal" id = "smp_asal"/>
					</td>
				</tr>
				<tr>
					<td>
						<label>No Ijazah
						 <span class="small">isi nomor ijazah siswa</span>
						</label>
					</td>
					<td>
						:
					</td>
					<td>
						<input type = "text" name = "no_ijazah" id = "no_ijazah"/>
					</td>
				</tr>
            </table>
               
            <h1>Data Orang Tua/Wali</h1>
            <table>
				<tr>
					<td width="250">
						<label>Nama Ayah
						 <span class="small">isi nama ayah</span>
						</label>
					</td>
					<td>
						:
					</td>	
					<td width="200">
						<input type = "text" name = "nama_ayah" id = "nama_ayah"/>
					</td>
				</tr>
				<tr>
					<td>
						<label>Pekerjaan Ayah
						 <span class="small">isi pekerjaan ayah</span>
						</label>
					</td>
					<td>
						:
					</td>
						
					<td>
						<input type = "text" name = "pekerjaan_ayah" id = "pekerjaan_ayah"/>
					</td>
				</tr>
				<tr>
					<td>
						<label>Nama ibu
							<span class = "small"> isi nama ibu </span>
						</label>
					</td>
					<td>
						:
					</td>
					<td>
						<input type = "text" name = "nama_ibu" id = "nama_ibu"/>
					</td>
				</tr>
				<tr>
					<td>
						<label>Pekerjaan ibu
							<span class = "small"> isi nama ibu </span>
						</label>
					</td>
					<td>
						:
					</td>
					<td>
						<input type = "text" name = "pekerjaan_ibu" id = "pekerjaan_ibu"/>
					</td>
				</tr>
				<tr>
					<td>
						<label>Nama wali
								<span class = "small"> isi nama wali </span>
						</label>
				   </td>
				   <td>
						:
					</td>
				   <td>
						<input type = "text" name = "nama_wali" id = "nama_wali"/>
				   </td>	
				</tr>
				<tr>
					<td>
						<label>Pekerjaan wali
								<span class = "small"> isi pekerjaan wali </span>
						</label>
				   </td>
				   <td>
						:
					</td>
				   <td>
						<input type = "text" name = "pekerjaan_wali" id = "pekerjaan_wali"/>
				   </td>	
				</tr>
				<tr>
					<td>
						<label>Alamat Wali
							<span class="small">isi alamat wali</span>
						</label>
					</td>
					<td>
						:
					</td>
					<td>
						 <input type="text" name="alamat_wali" id="alamat_wali" />
					<td>
				</tr>
			
				<tr>
					<td>
						<label>Kodepos
							<span class="small">isi kodepos wali</span>
						</label>
					</td>
					<td>
						:
					</td>
					<td>
						<select name="kode_pos_wali" id="kode_pos_wali ">
							<option value="NULL">---------Pilih----------</option>
							<?php 
						        $kode_pos = mysql_query("SELECT * FROM kode_pos");  
								// $result = mysql_fetch_array($nama_jurusan);
						        while($kode_pos_data = mysql_fetch_array($kode_pos))
						        {
						   		?>  
        							<option value="<?= $kode_pos_data[0]; ?>"><?= $kode_pos_data['0']?></option>  
								<?php  
								}  
								?>  	
						</select>
					</td>
				</tr>
               	<tr>
                	<td>
                		<label>No. Telepon/HP
                    		<span class="small">isi no telepon wali</span>
                		</label>
                	</td>
                	<td>
						:
					</td>
                	<td>
                		<input type="tel" name="no_tlp_wali" id="no_tlp_wali" />
                	</td>
				</tr>
               
				<tr>
                	<td>
                		<label>email
                    		<span class="small">isi email wali</span>
                		</label>
                	</td>
                	<td>
						:
					</td>
                	<td>
                		<input type="email" name="email_wali" id="email_wali" />
                	</td>
				</tr>
				<tr></tr>
				<tr></tr>
				<tr>
                  <td><input type="submit" name="submit" class="menuitem_red" value="Tambah"/></td>
                </tr> 
			</table>
			</form>
		</div>
		
    </div><!-- end of right content-->
            
                    
  </div>   <!--end of center content -->               
                    
                    
    
    
    <div class="clear"></div>
    </div> <!--end of main content-->
	
    
    <div class="footer">
        	<?php include 'footer.php'; ?>

    	
    </div>

</div>		
</body>
</html>